<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

	public function _initConfig() {

		$config = new Zend_Config_Ini ( APPLICATION_PATH . '/configs/application.ini' );
		$this->config = $config->toArray ();
		
		Zend_Registry::set ( 'config', $this->config );
	}

	/**
	 *路由
	 */
	protected function _initRoute() {

		//路由
		$this->bootstrap ( 'FrontController' );
		$front = $this->getResource ( 'FrontController' );
		$router = $front->getRouter ();
		
		/**
		 * 小站
		 */
		$siteHost = parse_url ( $this->config ['url'] ['site'] );
		$hostRoute = new Zend_Controller_Router_Route_Hostname ( $siteHost ['host'], array ( 
			'module' => 'site' 
		) );
		
		//主页
		$route = new Zend_Controller_Router_Route_Regex ( '^(.*)/?$', array ( 
			'controller' => 'index' , 'action' => 'index' 
		), array ( 
			1 => 'site_id' 
		), "%s" );
		$router->addRoute ( 'site_host', $hostRoute->chain ( $route ) );
		
		//模块首页
		$route = new Zend_Controller_Router_Route_Regex ( '^(.*)/(.*)/(.*)/?$', array ( 
			'action' => 'index' 
		), array ( 
			1 => 'site_id' , 2 => 'controller' , 3 => 'model_id' 
		), "%d/%s/%d" );
		$router->addRoute ( 'site_model_index', $hostRoute->chain ( $route ) );
		
		//模块首页 分页
		$route = new Zend_Controller_Router_Route_Regex ( '^(.*)/(.*)/(.*)_page_(.*).html$', array ( 
			'module' => 'site' , 'action' => 'index' 
		), array ( 
			1 => 'site_id' , 2 => 'controller' , 3 => 'model_id' , 4 => 'page_id' 
		), "%d/%s/%d_page_%d.html" );
		$router->addRoute ( 'site_model_page', $hostRoute->chain ( $route ) );
		
		//模块内容
		$route = new Zend_Controller_Router_Route_Regex ( '^(.*)/(.*)/(.*)/(.*).html$', array ( 
			'module' => 'site' , 'action' => 'show' 
		), array ( 
			1 => 'site_id' , 2 => 'controller' , 3 => 'model_id' , 4 => 'id' 
		), "%s/%s/%d/%d.html" );

		
		$router->addRoute ( 'site_model_content', $hostRoute->chain ( $route ) );
		
		//评论
		$route = new Zend_Controller_Router_Route_Regex ( '^comment/(add|delete|list).do$', array ( 
			'controller' => 'comment' 
		), array ( 
			1 => 'action' 
		), 'comment/%s.do' );
		$router->addRoute ( 'site_comment_do', $hostRoute->chain ( $route ) );
	
	}
}

